import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class LocalizationInfo with ChangeNotifier {
  String _localeKey = 'zh_CN';
  String get localeKey => _localeKey;

  LocalizationInfo() {
    initLanguage();
  }

  // 设置语言
  void setLocaleKey(String locale) async {
    final prefs = await SharedPreferences.getInstance();
    _localeKey = locale;
    prefs.setString('_localeKey', locale);
    notifyListeners(); // 通知监听者
  }

  // 初始化语言
  void initLanguage() async {
    final prefs = await SharedPreferences.getInstance();
    _localeKey = prefs.getString('_localeKey') ?? 'zh_CN';
    notifyListeners();
  }
}
